using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class Languages
    {
          #region Common
        public eLanguages Data;

        public Languages()
        {
            Data = new eLanguages();
		}

        ~Languages()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cLanguages objDAL = new cLanguages();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cLanguages objDAL = new cLanguages();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cLanguages objInfor = new cLanguages(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.LanguageID;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cLanguages objInfor = new cLanguages();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int UpdateStatus(int ID, int Status)
        {
            int nResult = 0;
            cLanguages objDAL = new cLanguages();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.Status = Status;
                objDAL.Save();
                nResult = objDAL.LanguageID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        private void MappingData(cLanguages objInfor)
        {
            objInfor.Description = Data.Description;
            objInfor.Image = Data.Image;
            objInfor.IsCurrent = Data.IsCurrent;
            objInfor.Status = Data.Status;
        }

        private void ConvertData(cLanguages objInfor)
        {
            Data.Description = objInfor.Description;
            Data.Image = objInfor.Image;
            Data.IsCurrent = objInfor.IsCurrent;
            Data.Status = objInfor.Status;
        }

        public DataTable SetDefaultLanguage( int CurrentLanguage)
        {
            DataTable tbResult = new DataTable();
            cLanguages objDAL = new cLanguages();
            tbResult = objDAL.SetDefaultLanguage(CurrentLanguage);
            return tbResult;
        }
        public int GetDefaultLanguage()
        {
            int nResult = 0;
            cLanguages objDAL = new cLanguages();
            nResult = objDAL.GetDefaultLanguage();
            return nResult;
        }

        public DataTable Search()
        {
            DataTable tbResult = new DataTable();
            cLanguages objDAL = new cLanguages();
            tbResult = objDAL.Search();
            return tbResult;
        }
       
        #endregion
    }
}
